package com.ocm.tourism.core.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.persistence.TableGenerator;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.beans.factory.annotation.Configurable;

@Entity
@Configurable
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public class Catalogues {

   @NotNull
   @Size(max = 255)
   private String name;

   @NotNull
   @Size(max = 255)
   private String cataloguesType;

   @Lob
   @org.hibernate.annotations.Type(type = "org.hibernate.type.TextType")
   private String content;

   @Size(max = 4000)
   private String description;

   @OneToMany(mappedBy = "catalogues",cascade=CascadeType.ALL,  orphanRemoval=true)
   private List<AttractionBusiness> attractionBusinesses = new ArrayList<AttractionBusiness>();

   @OneToMany(mappedBy = "catalogues",cascade=CascadeType.ALL,  orphanRemoval=true)
   private List<AttractionCatalogue> attractionCatalogues = new ArrayList<AttractionCatalogue>();
   
   @OneToMany(mappedBy = "catalogues",cascade=CascadeType.ALL,  orphanRemoval=true)
   private List<SightSeeing> sightseeings = new ArrayList<SightSeeing>();

   public String toString() {
      return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
   }

   public String getName() {
      return this.name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public String getCataloguesType() {
      return this.cataloguesType;
   }

   public void setCataloguesType(String cataloguesType) {
      this.cataloguesType = cataloguesType;
   }

   public String getContent() {
      return this.content;
   }

   public void setContent(String content) {
      this.content = content;
   }

   public String getDescription() {
      return this.description;
   }

   public void setDescription(String description) {
      this.description = description;
   }

   public List<AttractionBusiness> getAttractionBusinesses() {
      return attractionBusinesses;
   }

   public void setAttachtionBusinesses(List<AttractionBusiness> attractionBusinesses) {
      this.attractionBusinesses = attractionBusinesses;
   }

   public List<AttractionCatalogue> getAttractionCatalogues() {
      return attractionCatalogues;
   }

   public void setAttractionCatalogues(List<AttractionCatalogue> attractionCatalogues) {
      this.attractionCatalogues = attractionCatalogues;
   }

   public List<SightSeeing> getSightseeings() {
      return sightseeings;
   }

   public void setSightseeings(List<SightSeeing> sightseeings) {
      this.sightseeings = sightseeings;
   }

   public void addSightSeeing(SightSeeing sightSeeing){
      this.sightseeings.size();
      sightSeeing.setCatalogues(this);
      this.sightseeings.add(sightSeeing);
   }

   public void removeSightSeeing(long sightseeingId){
      this.sightseeings.size();
      SightSeeing sightSeeing = new SightSeeing();
      sightSeeing.setId(sightseeingId);
      this.sightseeings.remove(sightSeeing);
   }

   @Id
   @GeneratedValue(strategy=GenerationType.TABLE,generator="GEN_CATALOGUES")
   @TableGenerator(name = "GEN_CATALOGUES", table = "SEQUENCE_LIST", allocationSize = 1, initialValue = 1, pkColumnName = "NAME", valueColumnName = "NEXT_SEQUENCE", pkColumnValue = "CATALOGUES")
   private Long id;

   @Version
   @Column(name = "version")
   private Integer version;

   public Long getId() {
      return this.id;
   }

   public void setId(Long id) {
      this.id = id;
   }

   public Integer getVersion() {
      return this.version;
   }

   public void setVersion(Integer version) {
      this.version = version;
   }
}
